<%--
  Created by IntelliJ IDEA.
  User: srq
  Date: 2021/6/11
  Time: 18:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>result</title>
</head>
<body>
<h1>--------------test1-result--------------</h1>
队名：${teamName}

<h1>--------------test2-result--------------</h1>
球队编号：${requestScope.team.teamId}<br>
球队名称：${requestScope.team.teamName}<br>
球队位置：${requestScope.team.location}<br>

<h1>--------------test3-3-result--------------</h1>
<div>
    <button type="button" id="btn1">ajax请求自定义对象</button>
    <p id="res1"></p>
</div>

<h1>--------------test3-4-result--------------</h1>
<div>
    <button type="button" id="btn2">ajax请求List</button>
    <p id="res2"></p>
</div>

<h1>--------------test3-5-result--------------</h1>
<div>
    <button type="button" id="btn3">ajax请求Map</button>
    <p id="res3"></p>
</div>



</body>
</html>
<%--需要绝对路径，不然资源找不到--%>
<script src="/js/jquery2.1.4.js"></script>
<script>
    $(function(){
        $("#btn1").click(function (){
            $.ajax({
                type:"POST",
                url:"/result/test3_3.do",
                data:"",
                success:function (team){
                    alert("Data Saved:"+ team);
                    var id = team.teamId;
                    var name = team.teamName;
                    var loc = team.location;

                    $("#res1").html("id:"+id+",name:"+name+",location:"+loc);
                }
            });
        })
    });

    $(function(){
        $("#btn2").click(function (){
            $.ajax({
                type:"POST",
                url:"/result/test3_4.do",
                data:"",
                success:function (list){
                    alert("Data Saved:"+ list);
                    var str = "";
                    for (var i=0;i<list.length;i++){
                        var team = list[i];

                        str += "id:"+team.teamId+",name:"+team.teamName+",location:"+team.location+"<br>";
                    }
                    $("#res2").html(str);
                }
            });
        })
    });

    $(function(){
        $("#btn3").click(function (){
            $.ajax({
                type:"POST",
                url:"/result/test3_5.do",
                data:"",
                success:function (map){
                    alert("Data Saved:"+ map);
                    var str = "";
                    $.each(map,function (i,team){
                        str += "id:"+team.teamId+",name:"+team.teamName+",location:"+team.location+"<br>";
                    });
                    $("#res3").html(str);
                }
            });
        })
    });
</script>
